﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Address;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Siemens
{
	/// <summary>
	/// 一个西门子的客户端类，使用S7协议来进行数据交互 <br />
	/// A Siemens client class that uses the S7 protocol for data interaction
	/// </summary>
	/// <remarks>
	/// <note type="important">对于200smartPLC的V区，就是DB1.X，例如，V100=DB1.100，当然了你也可以输入V100</note>
	/// </remarks>
	/// <example>
	/// 地址支持的列表如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>中间寄存器</term>
	///     <term>M</term>
	///     <term>M100,M200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入寄存器</term>
	///     <term>I</term>
	///     <term>I100,I200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出寄存器</term>
	///     <term>Q</term>
	///     <term>Q100,Q200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>DB块寄存器</term>
	///     <term>DB</term>
	///     <term>DB1.100,DB1.200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>V寄存器</term>
	///     <term>V</term>
	///     <term>V100,V200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>V寄存器本质就是DB块1</term>
	///   </item>
	///   <item>
	///     <term>定时器的值</term>
	///     <term>T</term>
	///     <term>T100,T200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>未测试通过</term>
	///   </item>
	///   <item>
	///     <term>计数器的值</term>
	///     <term>C</term>
	///     <term>C100,C200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>未测试通过</term>
	///   </item>
	/// </list>
	/// <note type="important">对于200smartPLC的V区，就是DB1.X，例如，V100=DB1.100</note>
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="Usage" title="简单的短连接使用" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="Usage2" title="简单的长连接使用" />
	///
	/// 假设起始地址为M100，M100存储了温度，100.6℃值为1006，M102存储了压力，1.23Mpa值为123，M104，M105，M106，M107存储了产量计数，读取如下：
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample2" title="Read示例" />
	/// 以下是读取不同类型数据的示例
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample1" title="Read示例" />
	/// 以下是一个复杂的读取示例
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample3" title="Read示例" />
	/// </example>
	// Token: 0x0200004F RID: 79
	public class SiemensS7Net : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化一个西门子的S7协议的通讯对象 <br />
		/// Instantiate a communication object for a Siemens S7 protocol
		/// </summary>
		/// <param name="siemens">指定西门子的型号</param>
		// Token: 0x06000659 RID: 1625 RVA: 0x0001F374 File Offset: 0x0001D574
		public SiemensS7Net(SiemensPLCS siemens)
		{
			this.Initialization(siemens, string.Empty);
		}

		/// <summary>
		/// 实例化一个西门子的S7协议的通讯对象并指定Ip地址 <br />
		/// Instantiate a communication object for a Siemens S7 protocol and specify an IP address
		/// </summary>
		/// <param name="siemens">指定西门子的型号</param>
		/// <param name="ipAddress">Ip地址</param>
		// Token: 0x0600065A RID: 1626 RVA: 0x0001F4A4 File Offset: 0x0001D6A4
		public SiemensS7Net(SiemensPLCS siemens, string ipAddress)
		{
			this.Initialization(siemens, ipAddress);
		}

		/// <inheritdoc />
		// Token: 0x0600065B RID: 1627 RVA: 0x0001F5CE File Offset: 0x0001D7CE
		protected override INetMessage GetNewNetMessage()
		{
			return new S7Message();
		}

		/// <summary>
		/// 初始化方法<br />
		/// Initialize method
		/// </summary>
		/// <param name="siemens">指定西门子的型号 -&gt; Designation of Siemens</param>
		/// <param name="ipAddress">Ip地址 -&gt; IpAddress</param>
		// Token: 0x0600065C RID: 1628 RVA: 0x0001F5D8 File Offset: 0x0001D7D8
		private void Initialization(SiemensPLCS siemens, string ipAddress)
		{
			base.WordLength = 2;
			this.IpAddress = ipAddress;
			this.Port = 102;
			this.CurrentPlc = siemens;
			base.ByteTransform = new ReverseBytesTransform();
			switch (siemens)
			{
			case SiemensPLCS.S1200:
				this.plcHead1[21] = 0;
				break;
			case SiemensPLCS.S300:
				this.plcHead1[21] = 2;
				break;
			case SiemensPLCS.S400:
				this.plcHead1[21] = 3;
				this.plcHead1[17] = 0;
				break;
			case SiemensPLCS.S1500:
				this.plcHead1[21] = 0;
				break;
			case SiemensPLCS.S200Smart:
				this.plcHead1 = this.plcHead1_200smart;
				this.plcHead2 = this.plcHead2_200smart;
				break;
			case SiemensPLCS.S200:
				this.plcHead1 = this.plcHead1_200;
				this.plcHead2 = this.plcHead2_200;
				break;
			default:
				this.plcHead1[18] = 0;
				break;
			}
		}

		/// <summary>
		/// PLC的槽号，针对S7-400的PLC设置的<br />
		/// The slot number of PLC is set for PLC of s7-400
		/// </summary>
		// Token: 0x17000145 RID: 325
		// (get) Token: 0x0600065D RID: 1629 RVA: 0x0001F6B4 File Offset: 0x0001D8B4
		// (set) Token: 0x0600065E RID: 1630 RVA: 0x0001F6BC File Offset: 0x0001D8BC
		public byte Slot
		{
			get
			{
				return this.plc_slot;
			}
			set
			{
				this.plc_slot = value;
				this.plcHead1[21] = this.plc_rack * 32 + this.plc_slot;
			}
		}

		/// <summary>
		/// PLC的机架号，针对S7-400的PLC设置的<br />
		/// The frame number of the PLC is set for the PLC of s7-400
		/// </summary>
		// Token: 0x17000146 RID: 326
		// (get) Token: 0x0600065F RID: 1631 RVA: 0x0001F6E0 File Offset: 0x0001D8E0
		// (set) Token: 0x06000660 RID: 1632 RVA: 0x0001F6E8 File Offset: 0x0001D8E8
		public byte Rack
		{
			get
			{
				return this.plc_rack;
			}
			set
			{
				this.plc_rack = value;
				this.plcHead1[21] = this.plc_rack * 32 + this.plc_slot;
			}
		}

		/// <summary>
		/// 获取或设置当前PLC的连接方式，PG: 0x01，OP: 0x02，S7Basic: 0x03...0x10<br />
		/// Get or set the current PLC connection mode, PG: 0x01, OP: 0x02, S7Basic: 0x03...0x10
		/// </summary>
		// Token: 0x17000147 RID: 327
		// (get) Token: 0x06000661 RID: 1633 RVA: 0x0001F70C File Offset: 0x0001D90C
		// (set) Token: 0x06000662 RID: 1634 RVA: 0x0001F717 File Offset: 0x0001D917
		public byte ConnectionType
		{
			get
			{
				return this.plcHead1[20];
			}
			set
			{
				this.plcHead1[20] = value;
			}
		}

		/// <summary>
		/// 西门子相关的一个参数信息<br />
		/// A parameter information related to Siemens
		/// </summary>
		// Token: 0x17000148 RID: 328
		// (get) Token: 0x06000663 RID: 1635 RVA: 0x0001F723 File Offset: 0x0001D923
		// (set) Token: 0x06000664 RID: 1636 RVA: 0x0001F73E File Offset: 0x0001D93E
		public int LocalTSAP
		{
			get
			{
				return (int)this.plcHead1[16] * 256 + (int)this.plcHead1[17];
			}
			set
			{
				this.plcHead1[16] = BitConverter.GetBytes(value)[1];
				this.plcHead1[17] = BitConverter.GetBytes(value)[0];
			}
		}

		/// <summary>
		/// 获取当前西门子的PDU的长度信息，不同型号PLC的值会不一样。<br />
		/// Get the length information of the current Siemens PDU, the value of different types of PLC will be different.
		/// </summary>
		// Token: 0x17000149 RID: 329
		// (get) Token: 0x06000665 RID: 1637 RVA: 0x0001F763 File Offset: 0x0001D963
		public int PDULength
		{
			get
			{
				return this.pdu_length;
			}
		}

		/// <inheritdoc />
		// Token: 0x06000666 RID: 1638 RVA: 0x0001F76C File Offset: 0x0001D96C
		public override OperateResult<byte[]> ReadFromCoreServer(Socket socket, byte[] send, bool hasResponseData = true, bool usePackHeader = true)
		{
			OperateResult<byte[]> operateResult;
			for (;;)
			{
				operateResult = base.ReadFromCoreServer(socket, send, hasResponseData, usePackHeader);
				bool flag = !operateResult.IsSuccess;
				if (flag)
				{
					break;
				}
				bool flag2 = (int)operateResult.Content[2] * 256 + (int)operateResult.Content[3] != 7;
				if (flag2)
				{
					goto Block_2;
				}
			}
			return operateResult;
			Block_2:
			return operateResult;
		}

		/// <inheritdoc />
		// Token: 0x06000667 RID: 1639 RVA: 0x0001F7C8 File Offset: 0x0001D9C8
		protected override OperateResult InitializationOnConnect(Socket socket)
		{
			OperateResult<byte[]> operateResult = this.ReadFromCoreServer(socket, this.plcHead1, true, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(socket, this.plcHead2, true, true);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					this.pdu_length = (int)(base.ByteTransform.TransUInt16(operateResult2.Content.SelectLast(2), 0) - 28);
					bool flag3 = this.pdu_length < 200;
					if (flag3)
					{
						this.pdu_length = 200;
					}
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000668 RID: 1640 RVA: 0x0001F864 File Offset: 0x0001DA64
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadFromCoreServerAsync(Socket socket, byte[] send, bool hasResponseData = true, bool usePackHeader = true)
		{
			SiemensS7Net.<ReadFromCoreServerAsync>d__20 <ReadFromCoreServerAsync>d__ = new SiemensS7Net.<ReadFromCoreServerAsync>d__20();
			<ReadFromCoreServerAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadFromCoreServerAsync>d__.<>4__this = this;
			<ReadFromCoreServerAsync>d__.socket = socket;
			<ReadFromCoreServerAsync>d__.send = send;
			<ReadFromCoreServerAsync>d__.hasResponseData = hasResponseData;
			<ReadFromCoreServerAsync>d__.usePackHeader = usePackHeader;
			<ReadFromCoreServerAsync>d__.<>1__state = -1;
			<ReadFromCoreServerAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadFromCoreServerAsync>d__20>(ref <ReadFromCoreServerAsync>d__);
			return <ReadFromCoreServerAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000669 RID: 1641 RVA: 0x0001F8C8 File Offset: 0x0001DAC8
		[DebuggerStepThrough]
		protected override Task<OperateResult> InitializationOnConnectAsync(Socket socket)
		{
			SiemensS7Net.<InitializationOnConnectAsync>d__21 <InitializationOnConnectAsync>d__ = new SiemensS7Net.<InitializationOnConnectAsync>d__21();
			<InitializationOnConnectAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<InitializationOnConnectAsync>d__.<>4__this = this;
			<InitializationOnConnectAsync>d__.socket = socket;
			<InitializationOnConnectAsync>d__.<>1__state = -1;
			<InitializationOnConnectAsync>d__.<>t__builder.Start<SiemensS7Net.<InitializationOnConnectAsync>d__21>(ref <InitializationOnConnectAsync>d__);
			return <InitializationOnConnectAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 从PLC读取订货号信息<br />
		/// Reading order number information from PLC
		/// </summary>
		/// <returns>CPU的订货号信息 -&gt; Order number information for the CPU</returns>
		// Token: 0x0600066A RID: 1642 RVA: 0x0001F913 File Offset: 0x0001DB13
		[HslMqttApi("ReadOrderNumber", "获取到PLC的订货号信息")]
		public OperateResult<string> ReadOrderNumber()
		{
			return ByteTransformHelper.GetSuccessResultFromOther<string, byte[]>(base.ReadFromCoreServer(this.plcOrderNumber), (byte[] m) => Encoding.ASCII.GetString(m, 71, 20));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadOrderNumber" />
		// Token: 0x0600066B RID: 1643 RVA: 0x0001F948 File Offset: 0x0001DB48
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadOrderNumberAsync()
		{
			SiemensS7Net.<ReadOrderNumberAsync>d__23 <ReadOrderNumberAsync>d__ = new SiemensS7Net.<ReadOrderNumberAsync>d__23();
			<ReadOrderNumberAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadOrderNumberAsync>d__.<>4__this = this;
			<ReadOrderNumberAsync>d__.<>1__state = -1;
			<ReadOrderNumberAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadOrderNumberAsync>d__23>(ref <ReadOrderNumberAsync>d__);
			return <ReadOrderNumberAsync>d__.<>t__builder.Task;
		}

		// Token: 0x0600066C RID: 1644 RVA: 0x0001F98C File Offset: 0x0001DB8C
		private OperateResult CheckStartResult(byte[] content)
		{
			bool flag = content.Length < 19;
			OperateResult result;
			if (flag)
			{
				result = new OperateResult("Receive error");
			}
			else
			{
				bool flag2 = content[19] != 40;
				if (flag2)
				{
					result = new OperateResult("Can not start PLC");
				}
				else
				{
					bool flag3 = content[20] != 2;
					if (flag3)
					{
						result = new OperateResult("Can not start PLC");
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		// Token: 0x0600066D RID: 1645 RVA: 0x0001F9F4 File Offset: 0x0001DBF4
		private OperateResult CheckStopResult(byte[] content)
		{
			bool flag = content.Length < 19;
			OperateResult result;
			if (flag)
			{
				result = new OperateResult("Receive error");
			}
			else
			{
				bool flag2 = content[19] != 41;
				if (flag2)
				{
					result = new OperateResult("Can not stop PLC");
				}
				else
				{
					bool flag3 = content[20] != 7;
					if (flag3)
					{
						result = new OperateResult("Can not stop PLC");
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 对PLC进行热启动，目前仅适用于200smart型号<br />
		/// Hot start for PLC, currently only applicable to 200smart model
		/// </summary>
		/// <returns>是否启动成功的结果对象</returns>
		// Token: 0x0600066E RID: 1646 RVA: 0x0001FA5A File Offset: 0x0001DC5A
		[HslMqttApi]
		public OperateResult HotStart()
		{
			return ByteTransformHelper.GetResultFromOther<byte[]>(base.ReadFromCoreServer(this.S7_HOT_START), new Func<byte[], OperateResult>(this.CheckStartResult));
		}

		/// <summary>
		/// 对PLC进行冷启动，目前仅适用于200smart型号<br />
		/// Cold start for PLC, currently only applicable to 200smart model
		/// </summary>
		/// <returns>是否启动成功的结果对象</returns>
		// Token: 0x0600066F RID: 1647 RVA: 0x0001FA79 File Offset: 0x0001DC79
		[HslMqttApi]
		public OperateResult ColdStart()
		{
			return ByteTransformHelper.GetResultFromOther<byte[]>(base.ReadFromCoreServer(this.S7_COLD_START), new Func<byte[], OperateResult>(this.CheckStartResult));
		}

		/// <summary>
		/// 对PLC进行停止，目前仅适用于200smart型号<br />
		/// Stop the PLC, currently only applicable to the 200smart model
		/// </summary>
		/// <returns>是否启动成功的结果对象</returns>
		// Token: 0x06000670 RID: 1648 RVA: 0x0001FA98 File Offset: 0x0001DC98
		[HslMqttApi]
		public OperateResult Stop()
		{
			return ByteTransformHelper.GetResultFromOther<byte[]>(base.ReadFromCoreServer(this.S7_STOP), new Func<byte[], OperateResult>(this.CheckStopResult));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.HotStart" />
		// Token: 0x06000671 RID: 1649 RVA: 0x0001FAB8 File Offset: 0x0001DCB8
		[DebuggerStepThrough]
		public Task<OperateResult> HotStartAsync()
		{
			SiemensS7Net.<HotStartAsync>d__29 <HotStartAsync>d__ = new SiemensS7Net.<HotStartAsync>d__29();
			<HotStartAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<HotStartAsync>d__.<>4__this = this;
			<HotStartAsync>d__.<>1__state = -1;
			<HotStartAsync>d__.<>t__builder.Start<SiemensS7Net.<HotStartAsync>d__29>(ref <HotStartAsync>d__);
			return <HotStartAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ColdStart" />
		// Token: 0x06000672 RID: 1650 RVA: 0x0001FAFC File Offset: 0x0001DCFC
		[DebuggerStepThrough]
		public Task<OperateResult> ColdStartAsync()
		{
			SiemensS7Net.<ColdStartAsync>d__30 <ColdStartAsync>d__ = new SiemensS7Net.<ColdStartAsync>d__30();
			<ColdStartAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<ColdStartAsync>d__.<>4__this = this;
			<ColdStartAsync>d__.<>1__state = -1;
			<ColdStartAsync>d__.<>t__builder.Start<SiemensS7Net.<ColdStartAsync>d__30>(ref <ColdStartAsync>d__);
			return <ColdStartAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Stop" />
		// Token: 0x06000673 RID: 1651 RVA: 0x0001FB40 File Offset: 0x0001DD40
		[DebuggerStepThrough]
		public Task<OperateResult> StopAsync()
		{
			SiemensS7Net.<StopAsync>d__31 <StopAsync>d__ = new SiemensS7Net.<StopAsync>d__31();
			<StopAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<StopAsync>d__.<>4__this = this;
			<StopAsync>d__.<>1__state = -1;
			<StopAsync>d__.<>t__builder.Start<SiemensS7Net.<StopAsync>d__31>(ref <StopAsync>d__);
			return <StopAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 从PLC读取原始的字节数据，地址格式为I100，Q100，DB20.100，M100，长度参数以字节为单位<br />
		/// Read the original byte data from the PLC, the address format is I100, Q100, DB20.100, M100, length parameters in bytes
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100<br />
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <param name="length">读取的数量，以字节为单位<br />
		/// The number of reads, in bytes</param>
		/// <returns>
		/// 是否读取成功的结果对象 <br />
		/// Whether to read the successful result object</returns>
		/// <remarks>
		/// <inheritdoc cref="T:HslCommunication.Profinet.Siemens.SiemensS7Net" path="note" />
		/// </remarks>
		/// <example>
		/// 假设起始地址为M100，M100存储了温度，100.6℃值为1006，M102存储了压力，1.23Mpa值为123，M104，M105，M106，M107存储了产量计数，读取如下：
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample2" title="Read示例" />
		/// 以下是读取不同类型数据的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample1" title="Read示例" />
		/// </example>
		// Token: 0x06000674 RID: 1652 RVA: 0x0001FB84 File Offset: 0x0001DD84
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				List<byte> list = new List<byte>();
				ushort num = 0;
				while (num < length)
				{
					ushort num2 = (ushort)Math.Min((int)(length - num), this.pdu_length);
					operateResult.Content.Length = num2;
					OperateResult<byte[]> operateResult2 = this.Read(new S7AddressData[]
					{
						operateResult.Content
					});
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return operateResult2;
					}
					list.AddRange(operateResult2.Content);
					num += num2;
					bool flag3 = operateResult.Content.DataCode == 31 || operateResult.Content.DataCode == 30;
					if (flag3)
					{
						operateResult.Content.AddressStart += (int)(num2 / 2);
					}
					else
					{
						operateResult.Content.AddressStart += (int)(num2 * 8);
					}
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			return result;
		}

		/// <summary>
		/// 从PLC读取数据，地址格式为I100，Q100，DB20.100，M100，以位为单位 -&gt;
		/// Read the data from the PLC, the address format is I100，Q100，DB20.100，M100, in bits units
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt;
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <returns>是否读取成功的结果对象 -&gt; Whether to read the successful result object</returns>
		// Token: 0x06000675 RID: 1653 RVA: 0x0001FC9C File Offset: 0x0001DE9C
		private OperateResult<byte[]> ReadBitFromPLC(string address)
		{
			OperateResult<byte[]> operateResult = SiemensS7Net.BuildBitReadCommand(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = SiemensS7Net.AnalysisReadBit(operateResult2.Content);
				}
			}
			return result;
		}

		/// <summary>
		/// 一次性从PLC获取所有的数据，按照先后顺序返回一个统一的Buffer，需要按照顺序处理，两个数组长度必须一致，数组长度无限制<br />
		/// One-time from the PLC to obtain all the data, in order to return a unified buffer, need to be processed sequentially, two array length must be consistent
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100<br />
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <param name="length">数据长度数组<br />
		/// Array of data Lengths</param>
		/// <returns>是否读取成功的结果对象 -&gt; Whether to read the successful result object</returns>
		/// <exception cref="T:System.NullReferenceException"></exception>
		/// <remarks>
		/// <note type="warning">原先的批量的长度为19，现在已经内部自动处理整合，目前的长度为任意和长度。</note>
		/// </remarks>
		/// <example>
		/// 以下是一个高级的读取示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadExample3" title="Read示例" />
		/// </example>
		// Token: 0x06000676 RID: 1654 RVA: 0x0001FCF8 File Offset: 0x0001DEF8
		public OperateResult<byte[]> Read(string[] address, ushort[] length)
		{
			S7AddressData[] array = new S7AddressData[address.Length];
			for (int i = 0; i < address.Length; i++)
			{
				OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address[i], length[i]);
				bool flag = !operateResult.IsSuccess;
				if (flag)
				{
					return OperateResult.CreateFailedResult<byte[]>(operateResult);
				}
				array[i] = operateResult.Content;
			}
			return this.Read(array);
		}

		/// <summary>
		/// 读取西门子的地址数据信息，支持任意个数的数据读取<br />
		/// Read Siemens address data information, support any number of data reading
		/// </summary>
		/// <param name="s7Addresses">
		/// 西门子的数据地址<br />
		/// Siemens data address</param>
		/// <returns>返回的结果对象信息 -&gt; Whether to read the successful result object</returns>
		// Token: 0x06000677 RID: 1655 RVA: 0x0001FD60 File Offset: 0x0001DF60
		public OperateResult<byte[]> Read(S7AddressData[] s7Addresses)
		{
			bool flag = s7Addresses.Length > 19;
			OperateResult<byte[]> result;
			if (flag)
			{
				List<byte> list = new List<byte>();
				List<S7AddressData[]> list2 = SoftBasic.ArraySplitByLength<S7AddressData>(s7Addresses, 19);
				for (int i = 0; i < list2.Count; i++)
				{
					OperateResult<byte[]> operateResult = this.Read(list2[i]);
					bool flag2 = !operateResult.IsSuccess;
					if (flag2)
					{
						return operateResult;
					}
					list.AddRange(operateResult.Content);
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			else
			{
				result = this.ReadS7AddressData(s7Addresses);
			}
			return result;
		}

		/// <summary>
		/// 单次的读取，只能读取最多19个数组的长度，所以不再对外公开该方法
		/// </summary>
		/// <param name="s7Addresses">西门子的地址对象</param>
		/// <returns>返回的结果对象信息</returns>
		// Token: 0x06000678 RID: 1656 RVA: 0x0001FDF4 File Offset: 0x0001DFF4
		private OperateResult<byte[]> ReadS7AddressData(S7AddressData[] s7Addresses)
		{
			OperateResult<byte[]> operateResult = SiemensS7Net.BuildReadCommand(s7Addresses);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = SiemensS7Net.AnalysisReadByte(s7Addresses, operateResult2.Content);
				}
			}
			return result;
		}

		/// <summary>
		/// 基础的写入数据的操作支持<br />
		/// Operational support for the underlying write data
		/// </summary>
		/// <param name="entireValue">完整的字节数据 -&gt; Full byte data</param>
		/// <returns>是否写入成功的结果对象 -&gt; Whether to write a successful result object</returns>
		// Token: 0x06000679 RID: 1657 RVA: 0x0001FE4A File Offset: 0x0001E04A
		private OperateResult WriteBase(byte[] entireValue)
		{
			return ByteTransformHelper.GetResultFromOther<byte[]>(base.ReadFromCoreServer(entireValue), new Func<byte[], OperateResult>(SiemensS7Net.AnalysisWrite));
		}

		/// <summary>
		/// 将数据写入到PLC数据，地址格式为I100，Q100，DB20.100，M100，以字节为单位<br />
		/// Writes data to the PLC data, in the address format I100,Q100,DB20.100,M100, in bytes
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt;
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <param name="value">写入的原始数据 -&gt; Raw data written to</param>
		/// <returns>是否写入成功的结果对象 -&gt; Whether to write a successful result object</returns>
		/// <example>
		/// 假设起始地址为M100，M100,M101存储了温度，100.6℃值为1006，M102,M103存储了压力，1.23Mpa值为123，M104-M107存储了产量计数，写入如下：
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="WriteExample2" title="Write示例" />
		/// 以下是写入不同类型数据的示例
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="WriteExample1" title="Write示例" />
		/// </example>
		// Token: 0x0600067A RID: 1658 RVA: 0x0001FE64 File Offset: 0x0001E064
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				int num = value.Length;
				ushort num2 = 0;
				while ((int)num2 < num)
				{
					ushort num3 = (ushort)Math.Min(num - (int)num2, this.pdu_length);
					byte[] data = base.ByteTransform.TransByte(value, (int)num2, (int)num3);
					OperateResult<byte[]> operateResult2 = SiemensS7Net.BuildWriteByteCommand(operateResult, data);
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return operateResult2;
					}
					OperateResult operateResult3 = this.WriteBase(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						return operateResult3;
					}
					num2 += num3;
					operateResult.Content.AddressStart += (int)(num3 * 8);
				}
				result = OperateResult.CreateSuccessResult();
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Read(System.String,System.UInt16)" />
		// Token: 0x0600067B RID: 1659 RVA: 0x0001FF3C File Offset: 0x0001E13C
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			SiemensS7Net.<ReadAsync>d__39 <ReadAsync>d__ = new SiemensS7Net.<ReadAsync>d__39();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadAsync>d__39>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadBitFromPLC(System.String)" />
		// Token: 0x0600067C RID: 1660 RVA: 0x0001FF90 File Offset: 0x0001E190
		[DebuggerStepThrough]
		private Task<OperateResult<byte[]>> ReadBitFromPLCAsync(string address)
		{
			SiemensS7Net.<ReadBitFromPLCAsync>d__40 <ReadBitFromPLCAsync>d__ = new SiemensS7Net.<ReadBitFromPLCAsync>d__40();
			<ReadBitFromPLCAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadBitFromPLCAsync>d__.<>4__this = this;
			<ReadBitFromPLCAsync>d__.address = address;
			<ReadBitFromPLCAsync>d__.<>1__state = -1;
			<ReadBitFromPLCAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadBitFromPLCAsync>d__40>(ref <ReadBitFromPLCAsync>d__);
			return <ReadBitFromPLCAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Read(System.String[],System.UInt16[])" />
		// Token: 0x0600067D RID: 1661 RVA: 0x0001FFDC File Offset: 0x0001E1DC
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadAsync(string[] address, ushort[] length)
		{
			SiemensS7Net.<ReadAsync>d__41 <ReadAsync>d__ = new SiemensS7Net.<ReadAsync>d__41();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadAsync>d__41>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Read(HslCommunication.Core.Address.S7AddressData[])" />
		// Token: 0x0600067E RID: 1662 RVA: 0x00020030 File Offset: 0x0001E230
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadAsync(S7AddressData[] s7Addresses)
		{
			SiemensS7Net.<ReadAsync>d__42 <ReadAsync>d__ = new SiemensS7Net.<ReadAsync>d__42();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.s7Addresses = s7Addresses;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadAsync>d__42>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadS7AddressData(HslCommunication.Core.Address.S7AddressData[])" />
		// Token: 0x0600067F RID: 1663 RVA: 0x0002007C File Offset: 0x0001E27C
		[DebuggerStepThrough]
		private Task<OperateResult<byte[]>> ReadS7AddressDataAsync(S7AddressData[] s7Addresses)
		{
			SiemensS7Net.<ReadS7AddressDataAsync>d__43 <ReadS7AddressDataAsync>d__ = new SiemensS7Net.<ReadS7AddressDataAsync>d__43();
			<ReadS7AddressDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadS7AddressDataAsync>d__.<>4__this = this;
			<ReadS7AddressDataAsync>d__.s7Addresses = s7Addresses;
			<ReadS7AddressDataAsync>d__.<>1__state = -1;
			<ReadS7AddressDataAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadS7AddressDataAsync>d__43>(ref <ReadS7AddressDataAsync>d__);
			return <ReadS7AddressDataAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.WriteBase(System.Byte[])" />
		// Token: 0x06000680 RID: 1664 RVA: 0x000200C8 File Offset: 0x0001E2C8
		[DebuggerStepThrough]
		private Task<OperateResult> WriteBaseAsync(byte[] entireValue)
		{
			SiemensS7Net.<WriteBaseAsync>d__44 <WriteBaseAsync>d__ = new SiemensS7Net.<WriteBaseAsync>d__44();
			<WriteBaseAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteBaseAsync>d__.<>4__this = this;
			<WriteBaseAsync>d__.entireValue = entireValue;
			<WriteBaseAsync>d__.<>1__state = -1;
			<WriteBaseAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteBaseAsync>d__44>(ref <WriteBaseAsync>d__);
			return <WriteBaseAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Byte[])" />
		// Token: 0x06000681 RID: 1665 RVA: 0x00020114 File Offset: 0x0001E314
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			SiemensS7Net.<WriteAsync>d__45 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__45();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__45>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 读取指定地址的bool数据，地址格式为I100，M100，Q100，DB20.100<br />
		/// reads bool data for the specified address in the format I100，M100，Q100，DB20.100
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt;
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <returns>是否读取成功的结果对象 -&gt; Whether to read the successful result object</returns>
		/// <remarks>
		/// <note type="important">
		/// 对于200smartPLC的V区，就是DB1.X，例如，V100=DB1.100
		/// </note>
		/// </remarks>
		/// <example>
		/// 假设读取M100.0的位是否通断
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="ReadBool" title="ReadBool示例" />
		/// </example>
		// Token: 0x06000682 RID: 1666 RVA: 0x00020166 File Offset: 0x0001E366
		[HslMqttApi("ReadBool", "")]
		public override OperateResult<bool> ReadBool(string address)
		{
			return ByteTransformHelper.GetResultFromBytes<bool>(this.ReadBitFromPLC(address), (byte[] m) => m[0] > 0);
		}

		/// <summary>
		/// 读取指定地址的bool数组，地址格式为I100，M100，Q100，DB20.100<br />
		/// reads bool array data for the specified address in the format I100，M100，Q100，DB20.100
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt;
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <param name="length">读取的长度信息</param>
		/// <returns>是否读取成功的结果对象 -&gt; Whether to read the successful result object</returns>
		/// <remarks>
		/// <note type="important">
		/// 对于200smartPLC的V区，就是DB1.X，例如，V100=DB1.100
		/// </note>
		/// </remarks>
		// Token: 0x06000683 RID: 1667 RVA: 0x00020194 File Offset: 0x0001E394
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				int addressStart;
				ushort length2;
				int index;
				HslHelper.CalculateStartBitIndexAndLength(operateResult.Content.AddressStart, length, out addressStart, out length2, out index);
				operateResult.Content.AddressStart = addressStart;
				operateResult.Content.Length = length2;
				OperateResult<byte[]> operateResult2 = this.Read(new S7AddressData[]
				{
					operateResult.Content
				});
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<bool[]>(operateResult2.Content.ToBoolArray().SelectMiddle(index, (int)length));
				}
			}
			return result;
		}

		/// <summary>
		/// 写入PLC的一个位，例如"M100.6"，"I100.7"，"Q100.0"，"DB20.100.0"，如果只写了"M100"默认为"M100.0"<br />
		/// Write a bit of PLC, for example  "M100.6",  "I100.7",  "Q100.0",  "DB20.100.0", if only write  "M100" defaults to  "M100.0"
		/// </summary>
		/// <param name="address">起始地址，格式为"M100.6",  "I100.7",  "Q100.0",  "DB20.100.0" -&gt;
		/// Start address, format  "M100.6",  "I100.7",  "Q100.0",  "DB20.100.0"</param>
		/// <param name="value">写入的数据，True或是False -&gt; Writes the data, either True or False</param>
		/// <returns>是否写入成功的结果对象 -&gt; Whether to write a successful result object</returns>
		/// <example>
		/// 假设写入M100.0的位是否通断
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7Net.cs" region="WriteBool" title="WriteBool示例" />
		/// </example>
		// Token: 0x06000684 RID: 1668 RVA: 0x00020248 File Offset: 0x0001E448
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<byte[]> operateResult = SiemensS7Net.BuildWriteBitCommand(address, value);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				result = this.WriteBase(operateResult.Content);
			}
			return result;
		}

		/// <summary>
		/// [危险] 向PLC中写入bool数组，比如你写入M100,那么data[0]对应M100.0<br />
		/// [Danger] Write the bool array to the PLC, for example, if you write M100, then data[0] corresponds to M100.0
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt; Starting address, formatted as I100,mM100,Q100,DB20.100</param>
		/// <param name="values">要写入的bool数组，长度为8的倍数 -&gt; The bool array to write, a multiple of 8 in length</param>
		/// <returns>是否写入成功的结果对象 -&gt; Whether to write a successful result object</returns>
		/// <remarks>
		/// <note type="warning">
		/// 批量写入bool数组存在一定的风险，原因是只能批量写入长度为8的倍数的数组，否则会影响其他的位的数据，请谨慎使用。<br />
		/// There is a certain risk in batch writing to bool arrays, because you can only batch write arrays whose length is a multiple of 8, 
		/// otherwise it will affect other bit data. Please use it with caution.
		/// </note>
		/// </remarks>
		// Token: 0x06000685 RID: 1669 RVA: 0x0002027F File Offset: 0x0001E47F
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			return this.Write(address, SoftBasic.BoolArrayToByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadBool(System.String)" />
		// Token: 0x06000686 RID: 1670 RVA: 0x00020290 File Offset: 0x0001E490
		[DebuggerStepThrough]
		public override Task<OperateResult<bool>> ReadBoolAsync(string address)
		{
			SiemensS7Net.<ReadBoolAsync>d__50 <ReadBoolAsync>d__ = new SiemensS7Net.<ReadBoolAsync>d__50();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadBoolAsync>d__50>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000687 RID: 1671 RVA: 0x000202DC File Offset: 0x0001E4DC
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			SiemensS7Net.<ReadBoolAsync>d__51 <ReadBoolAsync>d__ = new SiemensS7Net.<ReadBoolAsync>d__51();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadBoolAsync>d__51>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Boolean)" />
		// Token: 0x06000688 RID: 1672 RVA: 0x00020330 File Offset: 0x0001E530
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			SiemensS7Net.<WriteAsync>d__52 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__52();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__52>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Boolean[])" />
		// Token: 0x06000689 RID: 1673 RVA: 0x00020384 File Offset: 0x0001E584
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			SiemensS7Net.<WriteAsync>d__53 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__53();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__53>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 读取指定地址的byte数据，地址格式I100，M100，Q100，DB20.100<br />
		/// Reads the byte data of the specified address, the address format I100,Q100,DB20.100,M100
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt;
		/// Starting address, formatted as I100,M100,Q100,DB20.100</param>
		/// <returns>是否读取成功的结果对象 -&gt; Whether to read the successful result object</returns>
		/// <example>参考<see cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Read(System.String,System.UInt16)" />的注释</example>
		// Token: 0x0600068A RID: 1674 RVA: 0x0001BA1E File Offset: 0x00019C1E
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <summary>
		/// 向PLC中写入byte数据，返回值说明<br />
		/// Write byte data to the PLC, return value description
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt; Starting address, formatted as I100,mM100,Q100,DB20.100</param>
		/// <param name="value">byte数据 -&gt; Byte data</param>
		/// <returns>是否写入成功的结果对象 -&gt; Whether to write a successful result object</returns>
		// Token: 0x0600068B RID: 1675 RVA: 0x0001BA2D File Offset: 0x00019C2D
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadByte(System.String)" />
		// Token: 0x0600068C RID: 1676 RVA: 0x000203D8 File Offset: 0x0001E5D8
		[DebuggerStepThrough]
		public Task<OperateResult<byte>> ReadByteAsync(string address)
		{
			SiemensS7Net.<ReadByteAsync>d__56 <ReadByteAsync>d__ = new SiemensS7Net.<ReadByteAsync>d__56();
			<ReadByteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte>>.Create();
			<ReadByteAsync>d__.<>4__this = this;
			<ReadByteAsync>d__.address = address;
			<ReadByteAsync>d__.<>1__state = -1;
			<ReadByteAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadByteAsync>d__56>(ref <ReadByteAsync>d__);
			return <ReadByteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Byte)" />
		// Token: 0x0600068D RID: 1677 RVA: 0x00020424 File Offset: 0x0001E624
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, byte value)
		{
			SiemensS7Net.<WriteAsync>d__57 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__57();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__57>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600068E RID: 1678 RVA: 0x00020478 File Offset: 0x0001E678
		public override OperateResult Write(string address, string value, Encoding encoding)
		{
			bool flag = value == null;
			if (flag)
			{
				value = string.Empty;
			}
			byte[] array = encoding.GetBytes(value);
			bool flag2 = encoding == Encoding.Unicode;
			if (flag2)
			{
				array = SoftBasic.BytesReverseByWord(array);
			}
			bool flag3 = this.CurrentPlc != SiemensPLCS.S200Smart;
			OperateResult result;
			if (flag3)
			{
				OperateResult<byte[]> operateResult = this.Read(address, 2);
				bool flag4 = !operateResult.IsSuccess;
				if (flag4)
				{
					result = operateResult;
				}
				else
				{
					bool flag5 = operateResult.Content[0] == byte.MaxValue;
					if (flag5)
					{
						result = new OperateResult<string>("Value in plc is not string type");
					}
					else
					{
						bool flag6 = operateResult.Content[0] == 0;
						if (flag6)
						{
							operateResult.Content[0] = 254;
						}
						bool flag7 = value.Length > (int)operateResult.Content[0];
						if (flag7)
						{
							result = new OperateResult<string>("String length is too long than plc defined");
						}
						else
						{
							result = this.Write(address, SoftBasic.SpliceArray<byte>(new byte[][]
							{
								new byte[]
								{
									operateResult.Content[0],
									(byte)value.Length
								},
								array
							}));
						}
					}
				}
			}
			else
			{
				result = this.Write(address, SoftBasic.SpliceArray<byte>(new byte[][]
				{
					new byte[]
					{
						(byte)value.Length
					},
					array
				}));
			}
			return result;
		}

		/// <summary>
		/// 使用双字节编码的方式，将字符串以 Unicode 编码写入到PLC的地址里，可以使用中文。<br />
		/// Use the double-byte encoding method to write the character string to the address of the PLC in Unicode encoding. Chinese can be used.
		/// </summary>
		/// <param name="address">起始地址，格式为I100，M100，Q100，DB20.100 -&gt; Starting address, formatted as I100,mM100,Q100,DB20.100</param>
		/// <param name="value">字符串的值</param>
		/// <returns>是否写入成功的结果对象</returns>
		// Token: 0x0600068F RID: 1679 RVA: 0x000205BC File Offset: 0x0001E7BC
		[HslMqttApi(ApiTopic = "WriteWString", Description = "写入unicode编码的字符串，支持中文")]
		public OperateResult WriteWString(string address, string value)
		{
			return this.Write(address, value, Encoding.Unicode);
		}

		/// <inheritdoc />
		// Token: 0x06000690 RID: 1680 RVA: 0x000205CC File Offset: 0x0001E7CC
		public override OperateResult<string> ReadString(string address, ushort length, Encoding encoding)
		{
			bool flag = length == 0;
			OperateResult<string> result;
			if (flag)
			{
				result = this.ReadString(address);
			}
			else
			{
				result = base.ReadString(address, length, encoding);
			}
			return result;
		}

		/// <summary>
		/// 读取西门子的地址的字符串信息，这个信息是和西门子绑定在一起，长度随西门子的信息动态变化的<br />
		/// Read the Siemens address string information. This information is bound to Siemens and its length changes dynamically with the Siemens information
		/// </summary>
		/// <param name="address">数据地址，具体的格式需要参照类的说明文档</param>
		/// <returns>带有是否成功的字符串结果类对象</returns>
		// Token: 0x06000691 RID: 1681 RVA: 0x000205FC File Offset: 0x0001E7FC
		[HslMqttApi("ReadS7String", "读取S7格式的字符串")]
		public OperateResult<string> ReadString(string address)
		{
			bool flag = this.CurrentPlc != SiemensPLCS.S200Smart;
			OperateResult<string> result;
			if (flag)
			{
				OperateResult<byte[]> operateResult = this.Read(address, 2);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult);
				}
				else
				{
					bool flag3 = operateResult.Content[0] == 0 || operateResult.Content[0] == byte.MaxValue;
					if (flag3)
					{
						result = new OperateResult<string>("Value in plc is not string type");
					}
					else
					{
						OperateResult<byte[]> operateResult2 = this.Read(address, (ushort)(2 + operateResult.Content[1]));
						bool flag4 = !operateResult2.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<string>(operateResult2);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<string>(Encoding.ASCII.GetString(operateResult2.Content, 2, operateResult2.Content.Length - 2));
						}
					}
				}
			}
			else
			{
				OperateResult<byte[]> operateResult3 = this.Read(address, 1);
				bool flag5 = !operateResult3.IsSuccess;
				if (flag5)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult3);
				}
				else
				{
					OperateResult<byte[]> operateResult4 = this.Read(address, (ushort)(1 + operateResult3.Content[0]));
					bool flag6 = !operateResult4.IsSuccess;
					if (flag6)
					{
						result = OperateResult.CreateFailedResult<string>(operateResult4);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<string>(Encoding.ASCII.GetString(operateResult4.Content, 1, operateResult4.Content.Length - 1));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 读取西门子的地址的字符串信息，这个信息是和西门子绑定在一起，长度随西门子的信息动态变化的<br />
		/// Read the Siemens address string information. This information is bound to Siemens and its length changes dynamically with the Siemens information
		/// </summary>
		/// <param name="address">数据地址，具体的格式需要参照类的说明文档</param>
		/// <returns>带有是否成功的字符串结果类对象</returns>
		// Token: 0x06000692 RID: 1682 RVA: 0x00020748 File Offset: 0x0001E948
		[HslMqttApi("ReadWString", "读取S7格式的双字节字符串")]
		public OperateResult<string> ReadWString(string address)
		{
			bool flag = this.CurrentPlc != SiemensPLCS.S200Smart;
			OperateResult<string> result;
			if (flag)
			{
				OperateResult<byte[]> operateResult = this.Read(address, 2);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult);
				}
				else
				{
					bool flag3 = operateResult.Content[0] == 0 || operateResult.Content[0] == byte.MaxValue;
					if (flag3)
					{
						result = new OperateResult<string>("Value in plc is not string type");
					}
					else
					{
						OperateResult<byte[]> operateResult2 = this.Read(address, (ushort)(2 + operateResult.Content[1] * 2));
						bool flag4 = !operateResult2.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<string>(operateResult2);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<string>(Encoding.Unicode.GetString(SoftBasic.BytesReverseByWord(operateResult2.Content.RemoveBegin(2))));
						}
					}
				}
			}
			else
			{
				OperateResult<byte[]> operateResult3 = this.Read(address, 1);
				bool flag5 = !operateResult3.IsSuccess;
				if (flag5)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult3);
				}
				else
				{
					OperateResult<byte[]> operateResult4 = this.Read(address, (ushort)(1 + operateResult3.Content[0] * 2));
					bool flag6 = !operateResult4.IsSuccess;
					if (flag6)
					{
						result = OperateResult.CreateFailedResult<string>(operateResult4);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<string>(Encoding.Unicode.GetString(operateResult4.Content, 1, operateResult4.Content.Length - 1));
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000693 RID: 1683 RVA: 0x00020898 File Offset: 0x0001EA98
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, string value, Encoding encoding)
		{
			SiemensS7Net.<WriteAsync>d__63 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__63();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.encoding = encoding;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__63>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.WriteWString(System.String,System.String)" />
		// Token: 0x06000694 RID: 1684 RVA: 0x000208F4 File Offset: 0x0001EAF4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteWStringAsync(string address, string value)
		{
			SiemensS7Net.<WriteWStringAsync>d__64 <WriteWStringAsync>d__ = new SiemensS7Net.<WriteWStringAsync>d__64();
			<WriteWStringAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteWStringAsync>d__.<>4__this = this;
			<WriteWStringAsync>d__.address = address;
			<WriteWStringAsync>d__.value = value;
			<WriteWStringAsync>d__.<>1__state = -1;
			<WriteWStringAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteWStringAsync>d__64>(ref <WriteWStringAsync>d__);
			return <WriteWStringAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000695 RID: 1685 RVA: 0x00020948 File Offset: 0x0001EB48
		[DebuggerStepThrough]
		public override Task<OperateResult<string>> ReadStringAsync(string address, ushort length, Encoding encoding)
		{
			SiemensS7Net.<ReadStringAsync>d__65 <ReadStringAsync>d__ = new SiemensS7Net.<ReadStringAsync>d__65();
			<ReadStringAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadStringAsync>d__.<>4__this = this;
			<ReadStringAsync>d__.address = address;
			<ReadStringAsync>d__.length = length;
			<ReadStringAsync>d__.encoding = encoding;
			<ReadStringAsync>d__.<>1__state = -1;
			<ReadStringAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadStringAsync>d__65>(ref <ReadStringAsync>d__);
			return <ReadStringAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadString(System.String)" />
		// Token: 0x06000696 RID: 1686 RVA: 0x000209A4 File Offset: 0x0001EBA4
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadStringAsync(string address)
		{
			SiemensS7Net.<ReadStringAsync>d__66 <ReadStringAsync>d__ = new SiemensS7Net.<ReadStringAsync>d__66();
			<ReadStringAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadStringAsync>d__.<>4__this = this;
			<ReadStringAsync>d__.address = address;
			<ReadStringAsync>d__.<>1__state = -1;
			<ReadStringAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadStringAsync>d__66>(ref <ReadStringAsync>d__);
			return <ReadStringAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadWString(System.String)" />
		// Token: 0x06000697 RID: 1687 RVA: 0x000209F0 File Offset: 0x0001EBF0
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadWStringAsync(string address)
		{
			SiemensS7Net.<ReadWStringAsync>d__67 <ReadWStringAsync>d__ = new SiemensS7Net.<ReadWStringAsync>d__67();
			<ReadWStringAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadWStringAsync>d__.<>4__this = this;
			<ReadWStringAsync>d__.address = address;
			<ReadWStringAsync>d__.<>1__state = -1;
			<ReadWStringAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadWStringAsync>d__67>(ref <ReadWStringAsync>d__);
			return <ReadWStringAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 从PLC中读取时间格式的数据<br />
		/// Read time format data from PLC
		/// </summary>
		/// <param name="address">地址</param>
		/// <returns>时间对象</returns>
		// Token: 0x06000698 RID: 1688 RVA: 0x00020A3B File Offset: 0x0001EC3B
		[HslMqttApi("ReadDateTime", "读取PLC的时间格式的数据，这个格式是s7格式的一种")]
		public OperateResult<DateTime> ReadDateTime(string address)
		{
			return ByteTransformHelper.GetResultFromBytes<DateTime>(this.Read(address, 8), new Func<byte[], DateTime>(SiemensDateTime.FromByteArray));
		}

		/// <summary>
		/// 向PLC中写入时间格式的数据<br />
		/// Writes data in time format to the PLC
		/// </summary>
		/// <param name="address">地址</param>
		/// <param name="dateTime">时间</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000699 RID: 1689 RVA: 0x00020A56 File Offset: 0x0001EC56
		[HslMqttApi("WriteDateTime", "写入PLC的时间格式的数据，这个格式是s7格式的一种")]
		public OperateResult Write(string address, DateTime dateTime)
		{
			return this.Write(address, SiemensDateTime.ToByteArray(dateTime));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadDateTime(System.String)" />
		// Token: 0x0600069A RID: 1690 RVA: 0x00020A68 File Offset: 0x0001EC68
		[DebuggerStepThrough]
		public Task<OperateResult<DateTime>> ReadDateTimeAsync(string address)
		{
			SiemensS7Net.<ReadDateTimeAsync>d__70 <ReadDateTimeAsync>d__ = new SiemensS7Net.<ReadDateTimeAsync>d__70();
			<ReadDateTimeAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<DateTime>>.Create();
			<ReadDateTimeAsync>d__.<>4__this = this;
			<ReadDateTimeAsync>d__.address = address;
			<ReadDateTimeAsync>d__.<>1__state = -1;
			<ReadDateTimeAsync>d__.<>t__builder.Start<SiemensS7Net.<ReadDateTimeAsync>d__70>(ref <ReadDateTimeAsync>d__);
			return <ReadDateTimeAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.DateTime)" />
		// Token: 0x0600069B RID: 1691 RVA: 0x00020AB4 File Offset: 0x0001ECB4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, DateTime dateTime)
		{
			SiemensS7Net.<WriteAsync>d__71 <WriteAsync>d__ = new SiemensS7Net.<WriteAsync>d__71();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.dateTime = dateTime;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<SiemensS7Net.<WriteAsync>d__71>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600069C RID: 1692 RVA: 0x00020B06 File Offset: 0x0001ED06
		public override string ToString()
		{
			return string.Format("SiemensS7Net {0}[{1}:{2}]", this.CurrentPlc, this.IpAddress, this.Port);
		}

		/// <summary>
		/// A general method for generating a command header to read a Word data
		/// </summary>
		/// <param name="s7Addresses">siemens address</param>
		/// <returns>Message containing the result object</returns>
		// Token: 0x0600069D RID: 1693 RVA: 0x00020B30 File Offset: 0x0001ED30
		public static OperateResult<byte[]> BuildReadCommand(S7AddressData[] s7Addresses)
		{
			bool flag = s7Addresses == null;
			if (flag)
			{
				throw new NullReferenceException("s7Addresses");
			}
			bool flag2 = s7Addresses.Length > 19;
			if (flag2)
			{
				throw new Exception(StringResources.Language.SiemensReadLengthCannotLargerThan19);
			}
			int num = s7Addresses.Length;
			byte[] array = new byte[19 + num * 12];
			array[0] = 3;
			array[1] = 0;
			array[2] = (byte)(array.Length / 256);
			array[3] = (byte)(array.Length % 256);
			array[4] = 2;
			array[5] = 240;
			array[6] = 128;
			array[7] = 50;
			array[8] = 1;
			array[9] = 0;
			array[10] = 0;
			array[11] = 0;
			array[12] = 1;
			array[13] = (byte)((array.Length - 17) / 256);
			array[14] = (byte)((array.Length - 17) % 256);
			array[15] = 0;
			array[16] = 0;
			array[17] = 4;
			array[18] = (byte)num;
			for (int i = 0; i < num; i++)
			{
				array[19 + i * 12] = 18;
				array[20 + i * 12] = 10;
				array[21 + i * 12] = 16;
				bool flag3 = s7Addresses[i].DataCode == 30 || s7Addresses[i].DataCode == 31;
				if (flag3)
				{
					array[22 + i * 12] = s7Addresses[i].DataCode;
					array[23 + i * 12] = (byte)(s7Addresses[i].Length / 2 / 256);
					array[24 + i * 12] = (byte)(s7Addresses[i].Length / 2 % 256);
				}
				else
				{
					array[22 + i * 12] = 2;
					array[23 + i * 12] = (byte)(s7Addresses[i].Length / 256);
					array[24 + i * 12] = (byte)(s7Addresses[i].Length % 256);
				}
				array[25 + i * 12] = (byte)(s7Addresses[i].DbBlock / 256);
				array[26 + i * 12] = (byte)(s7Addresses[i].DbBlock % 256);
				array[27 + i * 12] = s7Addresses[i].DataCode;
				array[28 + i * 12] = (byte)(s7Addresses[i].AddressStart / 256 / 256 % 256);
				array[29 + i * 12] = (byte)(s7Addresses[i].AddressStart / 256 % 256);
				array[30 + i * 12] = (byte)(s7Addresses[i].AddressStart % 256);
			}
			return OperateResult.CreateSuccessResult<byte[]>(array);
		}

		/// <summary>
		/// 生成一个位读取数据指令头的通用方法 -&gt;
		/// A general method for generating a bit-read-Data instruction header
		/// </summary>
		/// <param name="address">起始地址，例如M100.0，I0.1，Q0.1，DB2.100.2 -&gt;
		/// Start address, such as M100.0,I0.1,Q0.1,DB2.100.2
		/// </param>
		/// <returns>包含结果对象的报文 -&gt; Message containing the result object</returns>
		// Token: 0x0600069E RID: 1694 RVA: 0x00020DB0 File Offset: 0x0001EFB0
		public static OperateResult<byte[]> BuildBitReadCommand(string address)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = new byte[31];
				array[0] = 3;
				array[1] = 0;
				array[2] = (byte)(array.Length / 256);
				array[3] = (byte)(array.Length % 256);
				array[4] = 2;
				array[5] = 240;
				array[6] = 128;
				array[7] = 50;
				array[8] = 1;
				array[9] = 0;
				array[10] = 0;
				array[11] = 0;
				array[12] = 1;
				array[13] = (byte)((array.Length - 17) / 256);
				array[14] = (byte)((array.Length - 17) % 256);
				array[15] = 0;
				array[16] = 0;
				array[17] = 4;
				array[18] = 1;
				array[19] = 18;
				array[20] = 10;
				array[21] = 16;
				array[22] = 1;
				array[23] = 0;
				array[24] = 1;
				array[25] = (byte)(operateResult.Content.DbBlock / 256);
				array[26] = (byte)(operateResult.Content.DbBlock % 256);
				array[27] = operateResult.Content.DataCode;
				array[28] = (byte)(operateResult.Content.AddressStart / 256 / 256 % 256);
				array[29] = (byte)(operateResult.Content.AddressStart / 256 % 256);
				array[30] = (byte)(operateResult.Content.AddressStart % 256);
				result = OperateResult.CreateSuccessResult<byte[]>(array);
			}
			return result;
		}

		/// <summary>
		/// 生成一个写入字节数据的指令 -&gt; Generate an instruction to write byte data
		/// </summary>
		/// <param name="analysis">起始地址，示例M100,I100,Q100,DB1.100 -&gt; Start Address, example M100,I100,Q100,DB1.100</param>
		/// <param name="data">原始的字节数据 -&gt; Raw byte data</param>
		/// <returns>包含结果对象的报文 -&gt; Message containing the result object</returns>
		// Token: 0x0600069F RID: 1695 RVA: 0x00020F2C File Offset: 0x0001F12C
		public static OperateResult<byte[]> BuildWriteByteCommand(OperateResult<S7AddressData> analysis, byte[] data)
		{
			byte[] array = new byte[35 + data.Length];
			array[0] = 3;
			array[1] = 0;
			array[2] = (byte)((35 + data.Length) / 256);
			array[3] = (byte)((35 + data.Length) % 256);
			array[4] = 2;
			array[5] = 240;
			array[6] = 128;
			array[7] = 50;
			array[8] = 1;
			array[9] = 0;
			array[10] = 0;
			array[11] = 0;
			array[12] = 1;
			array[13] = 0;
			array[14] = 14;
			array[15] = (byte)((4 + data.Length) / 256);
			array[16] = (byte)((4 + data.Length) % 256);
			array[17] = 5;
			array[18] = 1;
			array[19] = 18;
			array[20] = 10;
			array[21] = 16;
			array[22] = 2;
			array[23] = (byte)(data.Length / 256);
			array[24] = (byte)(data.Length % 256);
			array[25] = (byte)(analysis.Content.DbBlock / 256);
			array[26] = (byte)(analysis.Content.DbBlock % 256);
			array[27] = analysis.Content.DataCode;
			array[28] = (byte)(analysis.Content.AddressStart / 256 / 256 % 256);
			array[29] = (byte)(analysis.Content.AddressStart / 256 % 256);
			array[30] = (byte)(analysis.Content.AddressStart % 256);
			array[31] = 0;
			array[32] = 4;
			array[33] = (byte)(data.Length * 8 / 256);
			array[34] = (byte)(data.Length * 8 % 256);
			data.CopyTo(array, 35);
			return OperateResult.CreateSuccessResult<byte[]>(array);
		}

		/// <summary>
		/// 生成一个写入位数据的指令 -&gt; Generate an instruction to write bit data
		/// </summary>
		/// <param name="address">起始地址，示例M100,I100,Q100,DB1.100 -&gt; Start Address, example M100,I100,Q100,DB1.100</param>
		/// <param name="data">是否通断 -&gt; Power on or off</param>
		/// <returns>包含结果对象的报文 -&gt; Message containing the result object</returns>
		// Token: 0x060006A0 RID: 1696 RVA: 0x000210D8 File Offset: 0x0001F2D8
		public static OperateResult<byte[]> BuildWriteBitCommand(string address, bool data)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] array = new byte[]
				{
					data ? 1 : 0
				};
				byte[] array2 = new byte[35 + array.Length];
				array2[0] = 3;
				array2[1] = 0;
				array2[2] = (byte)((35 + array.Length) / 256);
				array2[3] = (byte)((35 + array.Length) % 256);
				array2[4] = 2;
				array2[5] = 240;
				array2[6] = 128;
				array2[7] = 50;
				array2[8] = 1;
				array2[9] = 0;
				array2[10] = 0;
				array2[11] = 0;
				array2[12] = 1;
				array2[13] = 0;
				array2[14] = 14;
				array2[15] = (byte)((4 + array.Length) / 256);
				array2[16] = (byte)((4 + array.Length) % 256);
				array2[17] = 5;
				array2[18] = 1;
				array2[19] = 18;
				array2[20] = 10;
				array2[21] = 16;
				array2[22] = 1;
				array2[23] = (byte)(array.Length / 256);
				array2[24] = (byte)(array.Length % 256);
				array2[25] = (byte)(operateResult.Content.DbBlock / 256);
				array2[26] = (byte)(operateResult.Content.DbBlock % 256);
				array2[27] = operateResult.Content.DataCode;
				array2[28] = (byte)(operateResult.Content.AddressStart / 256 / 256);
				array2[29] = (byte)(operateResult.Content.AddressStart / 256);
				array2[30] = (byte)(operateResult.Content.AddressStart % 256);
				bool flag2 = operateResult.Content.DataCode == 28;
				if (flag2)
				{
					array2[31] = 0;
					array2[32] = 9;
				}
				else
				{
					array2[31] = 0;
					array2[32] = 3;
				}
				array2[33] = (byte)(array.Length / 256);
				array2[34] = (byte)(array.Length % 256);
				array.CopyTo(array2, 35);
				result = OperateResult.CreateSuccessResult<byte[]>(array2);
			}
			return result;
		}

		// Token: 0x060006A1 RID: 1697 RVA: 0x000212CC File Offset: 0x0001F4CC
		private static OperateResult<byte[]> AnalysisReadByte(S7AddressData[] s7Addresses, byte[] content)
		{
			int num = 0;
			for (int i = 0; i < s7Addresses.Length; i++)
			{
				bool flag = s7Addresses[i].DataCode == 31 || s7Addresses[i].DataCode == 30;
				if (flag)
				{
					num += (int)(s7Addresses[i].Length * 2);
				}
				else
				{
					num += (int)s7Addresses[i].Length;
				}
			}
			bool flag2 = content.Length >= 21 && (int)content[20] == s7Addresses.Length;
			OperateResult<byte[]> result;
			if (flag2)
			{
				byte[] array = new byte[num];
				int num2 = 0;
				int num3 = 0;
				for (int j = 21; j < content.Length; j++)
				{
					bool flag3 = j + 1 < content.Length;
					if (flag3)
					{
						bool flag4 = content[j] == byte.MaxValue && content[j + 1] == 4;
						if (flag4)
						{
							Array.Copy(content, j + 4, array, num3, (int)s7Addresses[num2].Length);
							j += (int)(s7Addresses[num2].Length + 3);
							num3 += (int)s7Addresses[num2].Length;
							num2++;
						}
						else
						{
							bool flag5 = content[j] == byte.MaxValue && content[j + 1] == 9;
							if (flag5)
							{
								int num4 = (int)content[j + 2] * 256 + (int)content[j + 3];
								bool flag6 = num4 % 3 == 0;
								if (flag6)
								{
									for (int k = 0; k < num4 / 3; k++)
									{
										Array.Copy(content, j + 5 + 3 * k, array, num3, 2);
										num3 += 2;
									}
								}
								else
								{
									for (int l = 0; l < num4 / 5; l++)
									{
										Array.Copy(content, j + 7 + 5 * l, array, num3, 2);
										num3 += 2;
									}
								}
								j += num4 + 4;
								num2++;
							}
							else
							{
								bool flag7 = content[j] == 5 && content[j + 1] == 0;
								if (flag7)
								{
									return new OperateResult<byte[]>((int)content[j], StringResources.Language.SiemensReadLengthOverPlcAssign);
								}
								bool flag8 = content[j] == 6 && content[j + 1] == 0;
								if (flag8)
								{
									return new OperateResult<byte[]>((int)content[j], StringResources.Language.SiemensError0006);
								}
								bool flag9 = content[j] == 10 && content[j + 1] == 0;
								if (flag9)
								{
									return new OperateResult<byte[]>((int)content[j], StringResources.Language.SiemensError000A);
								}
							}
						}
					}
				}
				result = OperateResult.CreateSuccessResult<byte[]>(array);
			}
			else
			{
				result = new OperateResult<byte[]>(StringResources.Language.SiemensDataLengthCheckFailed + " Msg:" + SoftBasic.ByteToHexString(content, ' '));
			}
			return result;
		}

		// Token: 0x060006A2 RID: 1698 RVA: 0x00021580 File Offset: 0x0001F780
		private static OperateResult<byte[]> AnalysisReadBit(byte[] content)
		{
			int num = 1;
			bool flag = content.Length >= 21 && content[20] == 1;
			OperateResult<byte[]> result;
			if (flag)
			{
				byte[] array = new byte[num];
				bool flag2 = 22 < content.Length;
				if (flag2)
				{
					bool flag3 = content[21] == byte.MaxValue && content[22] == 3;
					if (flag3)
					{
						array[0] = content[25];
					}
				}
				result = OperateResult.CreateSuccessResult<byte[]>(array);
			}
			else
			{
				result = new OperateResult<byte[]>(StringResources.Language.SiemensDataLengthCheckFailed);
			}
			return result;
		}

		// Token: 0x060006A3 RID: 1699 RVA: 0x00021600 File Offset: 0x0001F800
		private static OperateResult AnalysisWrite(byte[] content)
		{
			byte b = content[content.Length - 1];
			bool flag = b != byte.MaxValue;
			OperateResult result;
			if (flag)
			{
				result = new OperateResult((int)b, StringResources.Language.SiemensWriteError + b.ToString() + " Msg:" + SoftBasic.ByteToHexString(content, ' '));
			}
			else
			{
				result = OperateResult.CreateSuccessResult();
			}
			return result;
		}

		// Token: 0x040001AD RID: 429
		private byte[] plcHead1 = new byte[]
		{
			3,
			0,
			0,
			22,
			17,
			224,
			0,
			0,
			0,
			1,
			0,
			192,
			1,
			10,
			193,
			2,
			1,
			2,
			194,
			2,
			1,
			0
		};

		// Token: 0x040001AE RID: 430
		private byte[] plcHead2 = new byte[]
		{
			3,
			0,
			0,
			25,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			4,
			0,
			0,
			8,
			0,
			0,
			240,
			0,
			0,
			1,
			0,
			1,
			1,
			224
		};

		// Token: 0x040001AF RID: 431
		private byte[] plcOrderNumber = new byte[]
		{
			3,
			0,
			0,
			33,
			2,
			240,
			128,
			50,
			7,
			0,
			0,
			0,
			1,
			0,
			8,
			0,
			8,
			0,
			1,
			18,
			4,
			17,
			68,
			1,
			0,
			byte.MaxValue,
			9,
			0,
			4,
			0,
			17,
			0,
			0
		};

		// Token: 0x040001B0 RID: 432
		private SiemensPLCS CurrentPlc = SiemensPLCS.S1200;

		// Token: 0x040001B1 RID: 433
		private byte[] plcHead1_200smart = new byte[]
		{
			3,
			0,
			0,
			22,
			17,
			224,
			0,
			0,
			0,
			1,
			0,
			193,
			2,
			16,
			0,
			194,
			2,
			3,
			0,
			192,
			1,
			10
		};

		// Token: 0x040001B2 RID: 434
		private byte[] plcHead2_200smart = new byte[]
		{
			3,
			0,
			0,
			25,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			204,
			193,
			0,
			8,
			0,
			0,
			240,
			0,
			0,
			1,
			0,
			1,
			3,
			192
		};

		// Token: 0x040001B3 RID: 435
		private byte[] plcHead1_200 = new byte[]
		{
			3,
			0,
			0,
			22,
			17,
			224,
			0,
			0,
			0,
			1,
			0,
			193,
			2,
			77,
			87,
			194,
			2,
			77,
			87,
			192,
			1,
			9
		};

		// Token: 0x040001B4 RID: 436
		private byte[] plcHead2_200 = new byte[]
		{
			3,
			0,
			0,
			25,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			0,
			0,
			0,
			8,
			0,
			0,
			240,
			0,
			0,
			1,
			0,
			1,
			3,
			192
		};

		// Token: 0x040001B5 RID: 437
		private byte[] S7_STOP = new byte[]
		{
			3,
			0,
			0,
			33,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			14,
			0,
			0,
			16,
			0,
			0,
			41,
			0,
			0,
			0,
			0,
			0,
			9,
			80,
			95,
			80,
			82,
			79,
			71,
			82,
			65,
			77
		};

		// Token: 0x040001B6 RID: 438
		private byte[] S7_HOT_START = new byte[]
		{
			3,
			0,
			0,
			37,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			12,
			0,
			0,
			20,
			0,
			0,
			40,
			0,
			0,
			0,
			0,
			0,
			0,
			253,
			0,
			0,
			9,
			80,
			95,
			80,
			82,
			79,
			71,
			82,
			65,
			77
		};

		// Token: 0x040001B7 RID: 439
		private byte[] S7_COLD_START = new byte[]
		{
			3,
			0,
			0,
			39,
			2,
			240,
			128,
			50,
			1,
			0,
			0,
			15,
			0,
			0,
			22,
			0,
			0,
			40,
			0,
			0,
			0,
			0,
			0,
			0,
			253,
			0,
			2,
			67,
			32,
			9,
			80,
			95,
			80,
			82,
			79,
			71,
			82,
			65,
			77
		};

		// Token: 0x040001B8 RID: 440
		private byte plc_rack = 0;

		// Token: 0x040001B9 RID: 441
		private byte plc_slot = 0;

		// Token: 0x040001BA RID: 442
		private int pdu_length = 0;

		// Token: 0x040001BB RID: 443
		private const byte pduStart = 40;

		// Token: 0x040001BC RID: 444
		private const byte pduStop = 41;

		// Token: 0x040001BD RID: 445
		private const byte pduAlreadyStarted = 2;

		// Token: 0x040001BE RID: 446
		private const byte pduAlreadyStopped = 7;
	}
}
